const http = require('../../utils/http.js');
const app = getApp();
const regeneratorRuntime = require("../../utils/regenerator-runtime/runtime-module.js");
const { $Toast } = require('../../dist/base/index');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		orderStatus: false,
		orderDtail: [],
    onOff:true,
    totalJine:0,
	},


	//获取订单详情
	getOrderDetails() {
		var orderId = this.data.orderId;
		http.fetchApi('procedure_t', {
				p: 'R2002002|' + orderId
			})
			.then(res => {
				if (res.data.code == 1) {
					var orderDtail = res.data.results[0];
          var riderPhone = orderDtail.qsdh;
					this.setData({
						orderDtail,
            oid: orderDtail.oid,
            riderPhone
					})
          this.getShansong();
				}
			})
	},

  //获取闪送订单
  getShansong() {
    var oid = this.data.oid;
    http.fetchApi('procedure_t', { p: `R2002009|${oid}` }).then(res => {
      if (res.data.code == 1) {
        var jiadanArr = res.data.results;
        console.log(jiadanArr);
        this.setData({
          jiadanArr
        })
      }
    })
  },

	toRefund() {
		wx.navigateTo({
			url: '/pages/refund/refund?orderId='+this.data.orderId
		})
	},

  //确认送达
  confirmService(e){
    var formId = e.detail.formId;
    var uid = app.globalData.uid;
    http.fetchApi('procedure_t', {
      p: 'R2013001|' + formId + '|' + uid
    })
    
    wx.showModal({
      title: '提示',
      content: '是否确认送达?',
      success:(res1)=> {
        if (res1.confirm) {
          var orderId = this.data.orderId;
          http.fetchApi('p_order_qrsh', { p: `R2007009|${orderId}` }).then(res => {
            if (res.data.code == 1) {
              var codes = res.data.results[0].codes;
              if (codes == 1) {
                $Toast({
                  content: '确认成功',
                  type: 'success'
                });
                this.getOrderDetails();
                // http.showToast('确认成功' + '', '', '').then(() => {
                //   this.getOrderDetails();
                // })
              } else {
              
                $Toast({
                  content: '确认失败',
                  type: 'error'
                });
              }
            } else {
              $Toast({
                content: '确认失败',
                type: 'error'
              });
            }
          })
        } else if (res1.cancel) {
          
        }
      }
    })
    
  },

  //退款详情
  toTuiDetail(){
    wx.navigateTo({
      url: '/pages/refundDeatils/refundDeatils?orderId=' + this.data.orderId,
    })
  },

  handleXiaofei(e){
    console.log(e.detail.value)
    this.setData({
      totalJine: e.detail.value
    })
  },
  modalCancel() {
    this.setData({
      onOff: true
    })
  },
  modalConfirm() {
    this.setData({
      onOff: true
    })

    if (this.data.totalJine==0){
      $Toast({
        content: '加单金额不能为0',
        type: 'error'
      });
      return;
    }
    wx.navigateTo({
      url: '/pages/payment/payment?orderId=' + this.data.orderDtail.orderid + '&total=' + this.data.totalJine + '&ddId=' + this.data.orderDtail.oid+'&isXiaofei=1',
    })

  },
  //加小费
  tipping() {
    this.setData({
      onOff: false
    })
    var uid = app.globalData.uid;
    var bl_jine;
    var bl_orderid;
    var bl_zhifuzs;
  },

  //联系老铁
  cancatRider(){
    wx.makePhoneCall({
      phoneNumber:this.data.riderPhone,
    })
  },

  //评论
  toPinglun(){
    wx.navigateTo({
      url: '../evaluate/evaluate?orderId=' + this.data.orderId + '&qishou_id=' + this.data.orderDtail.qishou_id,
    })
  },
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		var orderId = options.orderId;
		this.setData({
			orderId
		})

		this.getOrderDetails();
   
	},

  
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
